package xyz.syyrjx.blog.util;

import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.common.Message;
import xyz.syyrjx.blog.entity.ai.AiDialogue;
import xyz.syyrjx.blog.entity.ai.chat.ChatMessage;

import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 大地崩坏苍蝇兽
 * @date 2023/12/29 10:10
 * @description 缓冲池
 * @since v0.0.1
 */
public class CachePool {
    private static List<String> allFoodName = null;

    public static List<String> getAllFood() {
        return allFoodName;
    }

    public static void setAllFood(List<String> allFood) {
        CachePool.allFoodName = allFood;
    }

    public static Map<String, Map<Integer, Integer>> aiIdGradeCountMap = null;
    static {
        CachePool.aiIdGradeCountMap = new HashMap<>();
        Map<Integer,Integer> qwenMap = new HashMap<>();
        qwenMap.put(0, Integer.MAX_VALUE);
        qwenMap.put(1, Integer.MAX_VALUE);
        qwenMap.put(2, Integer.MAX_VALUE);
        qwenMap.put(3, Integer.MAX_VALUE);
        aiIdGradeCountMap.put(ConstValuePool.QWEN_USAGE_COUNT, qwenMap);
        Map<Integer,Integer> wanxMap = new HashMap<>();
        wanxMap.put(0, 5);
        wanxMap.put(1, 8);
        wanxMap.put(2, 10);
        wanxMap.put(3, Integer.MAX_VALUE);
        aiIdGradeCountMap.put(ConstValuePool.WANX_USAGE_COUNT, wanxMap);

        Map<Integer,Integer> chatMap = new HashMap<>();
        chatMap.put(0, 15);
        chatMap.put(1, 20);
        chatMap.put(2, 25);
        chatMap.put(3, Integer.MAX_VALUE);
        aiIdGradeCountMap.put(ConstValuePool.CHAT_USAGE_COUNT, chatMap);

        Map<Integer,Integer> gpt4Map = new HashMap<>();
        gpt4Map.put(0,10);
        gpt4Map.put(1, 15);
        gpt4Map.put(2, 20);
        gpt4Map.put(3, Integer.MAX_VALUE);
        aiIdGradeCountMap.put(ConstValuePool.GPT4_USAGE_COUNT, gpt4Map);


    }

    // 简易对话锁
    public static final Map<String, Boolean> SIMPLE_AI_DIALOG_LOCK_MAP = new HashMap<>();

    // ai使用次数记录表
    public static Map<String, Map<String,Integer>> AI_USAGE_MAP = new HashMap<>();
    // ai对话记录表
    public static Map<String, Map<String,List<AiDialogue>>> AI_DIALOGUE_LIST_MAP = new HashMap<>();
    // ai合法身份表
    public static List<String> AI_IDENTITY_SEND_BY_SYSTEM = new LinkedList<>();
    // 通义千问参数对象
    public static Map<String, QwenParam> QWEN_PARAM_MAP = new HashMap<>();
    // 通义千问对话列表对象
    public static Map<String,List<Message>> QWEN_MESSAGE_DIALOGUES_MAP = new HashMap<>();
    // chat对话列表你
    public static Map<String,List<ChatMessage>> CHAT_MESSAGE_DIALOGUES_MAP = new HashMap<>();
    // gpt4对话列表你
    public static Map<String,List<ChatMessage>> GPT4_MESSAGE_DIALOGUES_MAP = new HashMap<>();
    public static void clearAiIdentity(String identity) {
        CachePool.AI_USAGE_MAP.remove(identity);
        CachePool.AI_DIALOGUE_LIST_MAP.remove(identity);
        CachePool.AI_IDENTITY_SEND_BY_SYSTEM.remove(identity);
        CachePool.QWEN_PARAM_MAP.remove(identity);
        CachePool.QWEN_MESSAGE_DIALOGUES_MAP.remove(identity);
        CachePool.CHAT_MESSAGE_DIALOGUES_MAP.remove(identity);
        CachePool.GPT4_MESSAGE_DIALOGUES_MAP.remove(identity);
    }

    public static void initAiIdentiy(String identity) {
        CachePool.AI_IDENTITY_SEND_BY_SYSTEM.add(identity);
        if (!CachePool.AI_USAGE_MAP.containsKey(identity)) {
            CachePool.AI_USAGE_MAP.put(identity, new HashMap<>());
        }
        if (!CachePool.AI_DIALOGUE_LIST_MAP.containsKey(identity)) {
            CachePool.AI_DIALOGUE_LIST_MAP.put(identity, new HashMap<>());
        }
    }
}
